<!-- 暂拆恢复  -->
<template>
  <view v-if="stepNmuber == 1">
    <view style="background: #fff;  padding: 20px 10px 10px; border-radius: 4px;" class="pb140">
      <uni-list class="userinfoselect-list" :avatar-circle="true">
        <uni-list-item v-for="(item, index) in tabeList" :key="index" direction="column" clickable>
          <template v-slot:header>
            <view class="userinfoselec-title text-left-right">
              <text>暂停业务编号{{item.ywbh}}</text>
              <checkbox :checked="item.select" @click="checkboxchange(item)" />
            </view>
            <view class="text-left-right">
              <text>计量点号：{{String(item.jldh)}}</text>
              <text>计量点总容量：{{String(item.jldzrl)}}</text>
            </view>
            <view class="text-left-right">
              <text>报停容量：{{String(item.btrl)}}</text>
              <text>报停日期：{{item.ztqdrq &&  item.ztqdrq.slice(0, 11)}}</text>
            </view>
          </template>
        </uni-list-item>
      </uni-list>
    </view>
    <view class="button-submit"><button type="primary" @click="formFubmit">暂拆恢复确认</button></view>
  </view>
  <view v-if="stepNmuber == 2">
    <business-signature @signatureConfirm="signatureConfirm" @signatureCancel="stepNmuber = 1" />
  </view>
  <cUserinfoSelect v-if="!paramForm.yhbh" @setYhbh="doSelectYhbh" />
</template>

<script setup lang="ts">
  import cUserinfoSelect from "@/pages/bspsd/components/userinfo-select.vue";
  import businessSignature from "@/pages/bspsd/components/business-signature.vue";
  import { getPhone } from "@/utils/storage";
  import { hlwZanTingHuiFu, YhYwBtjlQuery } from "@/api/request/ykgl";
  import { GetYhJbxx } from "@/api/request/GetYhJbxx";

  import { ref } from 'vue';
  const paramForm = ref({
    yhbh: '',
    lxsj: ''
  })
  const tabeList = ref([])
  const stepNmuber = ref(1)

  function formFubmit() {
    let list = tabeList.value.filter(item => item.select)
    if (list.length < 1) {
      uni.showToast({ icon: "none", title: "请选择需要恢复的记录" })
    } else {
      uni.showModal({
        title: "是否确定提交?",
        cancelText: "取消",
        confirmText: "确定",
        confirmColor: "#F43F3B",
        success: (res) => {
          if (res.confirm) {
            stepNmuber.value = 2
          }
        }
      })
    }
  }

  function doSelectYhbh(yhbh : string) {
    GetYhJbxx({
      data: { yhbh: yhbh },
      success: (res) => {
        if (res.length != 1) {
          uni.showModal({
            title: '错误提示',
            content: '查询数据时发生内部逻辑错误',
            showCancel: false,
            success: function () {
              uni.navigateBack()
            }
          })
          return
        }
        let obj = res[0] || {}
        paramForm.value.yhbh = obj.yhbh
        paramForm.value.lxsj = getPhone()
        YhYwBtjlQuery({
          data: { yhbh: yhbh },
          success: (result) => {
            if (result && result.length) {
              tabeList.value = result
            } else {
              uni.showModal({
                title: '提示',
                content: '当前户号暂无报停记录',
                showCancel: false,
                success: function () {
                  uni.navigateBack()
                }
              })
            }
          }
        })
      },
      fail: (_code, message) => {
        uni.showModal({ title: "提示", content: "提交失败，错误提示：" + message, showCancel: false })
        uni.navigateBack()
      }
    })
  }
  function checkboxchange(item) {
    item.select = !item.select
  }
  // 签名完成
  const signatureConfirm = (file) => {
    addClick(file)
  }
  const addClick = function (file) {
    let list = tabeList.value.filter(item => item.select)
    hlwZanTingHuiFu({
      data: {
        yhbh: paramForm.value.yhbh,
        lxsj: paramForm.value.lxsj,
        btjls: list,
        dzqm: file,
      },
      success: (result) => {
        uni.showModal({
          title: "提示",
          content: "你的业务已提交成功，稍后可以在：我的->业务办理中查询进度！",
          showCancel: false,
          success: () => {
            uni.navigateBack()
          },
        })
      },
      fail: (_code, message) => {
        uni.showModal({
          title: "错误提示",
          content: "提交失败：" + message,
          showCancel: false,
          success: () => {
            uni.navigateBack()
          }
        })
      }
    })
  }
</script>

<style lang="scss" scoped>

</style>